<%@page import="org.hibernate.validator.constraints.SafeHtml.Tag"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>项目产品详情</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody" style="padding: 0 10px">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="basePrdForm2">
                <div tabid="tabB" title="产品基本信息" lselected="true">
                    <div class="fieldset1 tabel_col clearFix">
                        <div class="fieldBox col_50">
                            <div class="label" style="color: pink">原${payeeTypCdNm}</div>
                            <div class="field">
                                <input name="splIdOld" id="splIdOld" type="text"
                                       class="ui-textbox" value="" readonly="readonly">
                            </div>
                        </div>

                        <div class="fieldBox col_50">
                            <div class="label" style="color: pink">原${payeeTypCdNm}(放款)账号</div>
                            <div class="field">
                                <input name="splAccNoIdOldFk" id="splAccNoIdOldFk" type="text"
                                       class="ui-textbox" value="" readonly="readonly">
                            </div>
                        </div>
                        <div id="yfl" class="fieldBox col_50" style="display: none">
                            <div class="label" style="color: pink;">原返利账号</div>
                            <div class="field">
                                <input name="splAccNoIdOldFl" id="splAccNoIdOldFl" type="text"
                                       class="ui-textbox" value="" readonly="readonly">
                            </div>
                        </div>
                        <div id="yflgps" class="fieldBox col_50" style="display: none">
                            <div class="label" style="color: pink">原销售返利账号</div>
                            <div class="field">
                                <input name="splAccNoIdOldFlGps" id="splAccNoIdOldFlGps"
                                       type="text" class="ui-textbox" value="" readonly="readonly">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <form id="basePrdForm1">
                <div tabid="tabA" title="产品基本信息" lselected="true">
                    <div class="fieldset1 tabel_col clearFix">
                        <div class="fieldBox col_50">
                            <div class="label">收款方类型</div>
                            <div class="field">
                                <input class="ui-textbox" name="payeeTypCdNm" id="payeeTypCdNm" type="text" value="${payeeTypCdNm}" disabled/>
                            </div>
                        </div>
                        <c:if test="${payeeTypCd != '1'}">
                            <div class="fieldBox col_50">
                                <div class="label">收款方</div>
                                <div class="field">
                                    <input name="cstSplId" id="cstSplId" type="text" value=""
                                           placeholder="请选择" onchange="getCstBankNo();" ltype="combobox" validate="{required:true}">
                                    <span class="requiredSymbol">*</span>
                                    <div class="combo_itemList_wrap"></div>
                                </div>
                            </div>
                        </c:if>
                        <c:if test="${payeeTypCd == '1'}">
                            <div class="fieldBox col_50">
                                <div class="label">收款方</div>
                                <div class="field">
                                    <input name="splId" id="splId" type="text" value=""
                                           placeholder="请选择" onchange="getSplBankNo();" ltype="combobox" validate="{required:true}">
                                    <span class="requiredSymbol">*</span>
                                    <div class="combo_itemList_wrap"></div>
                                </div>
                            </div>
                        </c:if>
                        <!-- 供应商ID -->
                        <div class="fieldBox col_50">
                            <div class="label">账号类型</div>
                            <div class="field">
                                <select name="purpCd" id="purpCd" data-value=" "
                                        validate="{required:true,select:true}" onchange="purpCdChange();">
                                    <c:forEach items="${purpCdList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <%--供应商--%>
                        <c:if test="${payeeTypCd == '1'}">
                            <div class="fieldBox col_50">
                                <div id="fk" class="label">账号</div>
                                <div id="fl" class="label" style="display: none">返利账号</div>
                                <div id="flGps" class="label" style="display: none">销售返利账号</div>
                                <div class="field">
                                    <input name="splAccNoId" id="splAccNoId" type="text" value=""
                                           placeholder="请选择" ltype="combobox" validate="{required:true}">
                                    <span class="requiredSymbol">*</span>
                                    <div class="combo_itemList_wrap"></div>
                                </div>
                            </div>
                        </c:if>
                        <c:if test="${payeeTypCd != '1'}">
                            <div class="fieldBox col_50">
                                <div id="fk1" class="label">账号</div>
                                <div class="field">
                                    <input name="cstSplAccNoId" id="cstSplAccNoId" type="text" value=""
                                           placeholder="请选择" ltype="combobox" validate="{required:true}">
                                    <span class="requiredSymbol">*</span>
                                    <div class="combo_itemList_wrap"></div>
                                </div>
                            </div>
                        </c:if>
                    </div>
                </div>
                <div id="btnsBox" class="btnsBox">
                    <br />
                    <br /> <span id="saveBtn" class="sq-button sq-button-round"
                                 onclick="savePrjBscInfo()"> <!-- <i class="sqBtnIco_10"></i> -->保存
						</span> <span id="cancelBtn" class="sq-button sq-button-round"
                                      onclick="cancelBtn()"> <!-- <i class="sqBtnIco_14"></i> -->取消
						</span>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    var prjPrdId = '${prjPrdId}';
    var searchSplNm = '${prdBscInfoVO.splNm}';
    var buOrgCd = '${buOrgCd}';
    var accIdFl = '${accIdFl}';
    var accNoFl = '${accNoFl}';
    var accIdFlGps = '${accIdFlGps}';
    var accNoFlGps = '${accNoFlGps}';
    var bankId='${accId}';
    $(function () {
        initHtml();
    });

    function purpCdChange(){
        var purpCd = $("#purpCd").val();
        var form = $("#basePrdForm1").ligerForm({
            validate: true
        });
        if(${payeeTypCd == '1'}) {
            if(purpCd == '1'){
                $("#fk").show();
                $("#fl").hide();
                $("#flGps").hide();
                bankId='${accId}';
                getSplBankNo();
            }else if(purpCd == '2'){
                $("#fk").hide();
                $("#fl").show();
                $("#flGps").hide();
                bankId=accIdFl;
                getSplBankNo();
            }else if(purpCd==11) {
                $("#fk").hide();
                $("#fl").hide();
                $("#flGps").show();
                bankId = accIdFlGps;
                getSplBankNo();
            }else{
                $.ligerDialog.SQalert({
                    content : "系统暂不支持!",
                    SQ_type : "error"
                });
            }
        } else {
            if(purpCd == '1') {
                $("#fk").show();
                $("#fl").hide();
                $("#flGps").hide();
                bankId='${accId}';
                getCstBankNo();
            } else {
                $.ligerDialog.SQalert({
                    content : "系统暂不支持!",
                    SQ_type : "error"
                });
            }
        }
    }

    function initHtml(){
        var form = $("#basePrdForm1").ligerForm({
            validate: true
        });
        var form = $("#basePrdForm2").ligerForm({
            validate: true
        });
        liger.get("splIdOld").setValue('${splNm}');
        liger.get("splAccNoIdOldFk").setValue('${accNo}');

        if((accIdFl!=""&&accIdFl!=null)&&(accNoFl!=""&&accNoFl!=null)){
            $("#yfl").show();
            liger.get("splAccNoIdOldFl").setValue('${accNoFl}');
        }
        if((accIdFlGps!=""&&accIdFlGps!=null)&&(accNoFlGps!=""&&accNoFlGps!=null)){
            $("#yflgps").show();
            liger.get("splAccNoIdOldFlGps").setValue('${accNoFlGps}');
        }
        if ('${payeeTypCd}' == '1') {
            getSplBankNo();
        } else {
            liger.get("cstSplId").setValue('${cstId}');
            getCstBankNo();
        }
    }

    var audStsCdList = new Array();
    if(buOrgCd!=ProjectConstant.CODE_BU_ORG_CD_CAR){
        audStsCdList.push(CommonConstant.C_AUD_ADNWAY_CODE);
    }
    audStsCdList.push(CommonConstant.C_AUD_PASS_CODE);
    var audStsCdListArr = JSON.stringify(audStsCdList);

    var comboGrid_defaultValue1='${splId}';
    var comboGrid_defaultText1 = '${splNm}';
    var isInit_setSearchComboVal1 = false;
    var COMBO_SPL = $("#splId").ligerComboBox({
        width: 300,
        selectBoxWidth: 300,
        selectBoxHeight: 240,
        valueField: 'id',
        textField: 'splNm',
        isMultiSelect: true,
        isSingleCheck: true,
        grid: getSplGridOptions(true),
        parms: {condition:JSON.stringify([{"op":"like","field":"splNm","value": comboGrid_defaultText1,"type":"text"}])},
        condition: {
            labelWidth: 0,
            space: 5,
            fields: [{ name: 'splNm', width: 90, type:'text' , keyName: 'id'}]
        },
        delayLoadGrid: false,
        onChangeValue: function (value) {
            if (COMBO_SPL) {
                if (value=="") comboGrid_defaultValue1 = ""; //如果点击清空'x'，就滞空初始值
                $("#splId").show_ligerComboItems(".combo_itemList_wrap");
            };
            SetIframe_height();
        }
    });

    function getSplGridOptions(checkbox){
        var options = {
            columns: [
                { display: '供应商名称', name: 'splNm',
                    render: function (rowdata, rowindex, value, column) {
                        value ==null?"":value;
                        var h = '';
                        if(rowdata.audStsCd){
                            if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
                                h+='<i class="ico_flasher"></i>';
                            }
                        }
                        h+=value;
                        return h;
                    },
                    minWidth: 150 },
                { display: '企业性质', name: 'corpTypCdNm', minWidth: 100 },
                { display: '经营范围', name: 'bizScope', minWidth: 150 },
                { display: '注册资本', name: 'regCapAmt', minWidth: 50 },
                { display: '实收资本', name: 'paidCapAmt', minWidth: 50 },
            ],
            switchPageSizeApplyComboBox: false,
            url: '<%=path%>/project/prjprdbscinfo/splInitList.do?audStsCdList='+audStsCdListArr,
            method: 'get',
            dataAction: 'local',
            root:'rows',
            record:'total',
            pageSize: 10,
            usePagerOnLessPagesize: false,
            cssClass: "SMALL_grid",
            isSingleCheck: true,
            frozen: false,
            isSelected: function (rowdata) {
                if (comboGrid_defaultValue1 == "") return false;
                var defaultItems = comboGrid_defaultValue1.split(";");
                if(!isInit_setSearchComboVal1) { //只在初始化时执行一次，在onAfterShowData后改变
                    for (var i = 0; i < defaultItems.length; i++) {
                        if(rowdata[COMBO_SPL.options.valueField] == defaultItems[i]) {
                            return true;
                        }
                    };
                };
                return false;
            },
            onAfterShowData: function (currentData) {
                if(!isInit_setSearchComboVal1) { //只在初始化时执行一次，在onAfterShowData后改变
                    COMBO_SPL.setInputValue(comboGrid_defaultValue1, comboGrid_defaultText1, true);
                    isInit_setSearchComboVal1 = true;
                }
            }
        };
        return options;
    }

    function getCstBankNo() {
        var cstId = liger.get("cstSplId").selectedValue;
        $.ajax({
            url: '<%=path%>/customer/cstbank/initBanks.do?cstId=' + cstId,
            dataType:'json',
            success: function (res) {
                var cstSplAccNoId = liger.get('cstSplAccNoId');
                cstSplAccNoId.gridManager.loadData(res);
                cstSplAccNoId.clear();
                COMBO_CST_BANK.setInputValue(bankId, comboGrid_defaultText2, true);
            }
        });
    }

    function getSplBankNo(){
        var splId = liger.get("splId").selectedValue;
        var purpCd = $("#purpCd").val();
        if(splId==undefined){
            return;
        }
        var audStsCdList = new Array();
        if(buOrgCd!=ProjectConstant.CODE_BU_ORG_CD_CAR){
            audStsCdList.push(CommonConstant.C_AUD_ADNWAY_CODE);
        }
        audStsCdList.push(CommonConstant.C_AUD_PASS_CODE);
        var audStsCdListArr = JSON.stringify(audStsCdList);
        $.ajax({
            url: '<%=path%>/project/prjprdbscinfo/getSplBankAccNoBySplId.do?splId='+splId+'&purpCd='+purpCd+'&&audStsCdList='+audStsCdListArr,
            dataType:'json',
            success: function (res) {
                var splAccNoId = liger.get('splAccNoId');
                splAccNoId.gridManager.loadData(res);
                splAccNoId.clear();
                if (purpCd == '1') {
                    COMBO_BANK.setInputValue(bankId, comboGrid_defaultText2, true);
                } else if (purpCd == '2') {
                    COMBO_BANK.setInputValue(accIdFl, accNoFl, true);
                } else if (purpCd == '11') {
                    COMBO_BANK.setInputValue(accIdFlGps, accNoFlGps, true);
                }
            }
        });
    }

    var comboGrid_defaultValue2='${accId}';
    var comboGrid_defaultText2 = '${accNo}';
    var isInit_setSearchComboVal2 = false;
    var accNo;
    // 供应商账号下拉框
    var COMBO_BANK=$("#splAccNoId").ligerComboBox({
        width: 300,
        selectBoxWidth: 300,
        selectBoxHeight: 240,
        valueField: 'id',
        textField: 'accNo',
        isSingleCheck: true,
        condition: {
            labelWidth: 0,
            space: 5,
            fields: [{ name: 'accNo', width: 90, type:'text' , keyName: 'id'}]

        },
        conditionSearchClick: function (a) {
            if (a.rules.length == 0) {
                accNo = '';
            } else {
                accNo = a.rules[0].value;
            }
            COMBO_BANK.grid.options.newPage = 1;
            COMBO_BANK.grid.loadServerData({'accNo': accNo, 'splId': liger.get("splId").selectedValue, 'page' : '1'});
        },
        grid: getSplBankNoGridOptions(true, audStsCdListArr, bankId),
        delayLoadGrid: false
    });

    // 获取供应商账号的列表
    function getSplBankNoGridOptions(checkbox, audStsCdListArr, bankId){
        var purpCd = $("#purpCd").val();
        var options = {
            url: '<%=path%>/project/prjprdbscinfo/getSplBankAccNoBySplId.do?purpCd=' + purpCd + '&audStsCdList=' + audStsCdListArr,
            columns: [
                { display: 'id', name: 'id', minWidth: 150,hide:true },
                { display: '收款人', name: 'rcptUnt',
                    render: function (rowdata, rowindex, value, column) {
                        value ==null?"":value;
                        var h = '';
                        if(rowdata.audStsCd){
                            if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
                                h+='<i class="ico_flasher"></i>';
                            }
                        }
                        h+=value;
                        return h;
                    },
                    minWidth: 150 },
                { display: '收款账号', name: 'accNo', minWidth: 150 }
            ],
            method: 'get',
            dataAction: 'server',
            root:'rows',
            record:'total',
            pageSize: 10,
            cssClass: "SMALL_grid",
            isSingleCheck: true,
            frozen: false,
            isSelected: function (rowdata) {
                if (comboGrid_defaultValue2 == "") return false;
                var defaultItems = comboGrid_defaultValue2.split(";");
                if(!isInit_setSearchComboVal2) { //只在初始化时执行一次，在onAfterShowData后改变
                    for (var i = 0; i < defaultItems.length; i++) {
                        if(rowdata[COMBO_BANK.options.valueField] == defaultItems[i]) {
                            return true;
                        }
                    };
                };
                return false;
            },
            onAfterShowData: function (currentData) {
                if(!isInit_setSearchComboVal2) { //只在初始化时执行一次，在onAfterShowData后改变
                    COMBO_BANK.setInputValue(comboGrid_defaultValue2, comboGrid_defaultText2, true);
                }
            },
            onChangePage: function (page) {
                COMBO_BANK.grid.options.newPage = page;
                COMBO_BANK.grid.setParm('splId', liger.get("splId").selectedValue);
                COMBO_BANK.grid.setParm('accNo', accNo);
            }
        };
        return options;
    }

    //承租人、担保人列表
    var comboGrid_defaultValue6='${cstId}';
    var comboGrid_defaultText6 = '${splNm}';
    var cstNm;
    var isInit_setSearchComboVal6 = false;
    var COMBO_CST = $("#cstSplId").ligerComboBox({
        width: 300,
        selectBoxWidth: 300,
        selectBoxHeight: 240,
        valueField: 'cstId',
        textField: 'cstNm',
        isMultiSelect: true,
        isSingleCheck: true,
        condition: {
            labelWidth: 0,
            space: 5,
            fields: [{ name: 'cstNm', width: 90, type:'text' , keyName: 'cstId'}]
        },
        conditionSearchClick: function (a) {
            if (a.rules.length == 0) {
                cstNm = '';
            } else {
                cstNm = a.rules[0].value;
            }
            COMBO_CST.grid.options.newPage = 1;
            COMBO_CST.grid.loadServerData({'cstNm': cstNm, 'cstSplId': liger.get("cstSplId").selectedValue, 'page' : '1'});
        },
        grid: getCstSplGridOptions(true),
        delayLoadGrid: false
    });

    function getCstSplGridOptions(checkbox){
        var options = {
            columns: [
                {display: "客户名称", name: 'cstNm', minWidth: 100},
                {display: '证件/组织机构代码', name: 'certNo', minWidth: 200}
            ],
            url: '<%=path%>/project/prjcstbscInfo/initList.do' ,
            method: 'get',
            dataAction: 'local',
            root:'rows',
            record:'total',
            pageSize: 10,
            usePagerOnLessPagesize: false,
            cssClass: "SMALL_grid",
            isSingleCheck: true,
            frozen: false,
            isSelected: function (rowdata) {
                if (comboGrid_defaultValue6 == "") return false;
                if(!isInit_setSearchComboVal6) { //只在初始化时执行一次，在onAfterShowData后改变
                    if(rowdata[COMBO_CST.options.valueField] == comboGrid_defaultValue6) {
                        return true;
                    }
                };
                return false;
            },
            onAfterShowData: function (currentData) {
                if(!isInit_setSearchComboVal6) { //只在初始化时执行一次，在onAfterShowData后改变
                    COMBO_CST.setInputValue(comboGrid_defaultValue6, comboGrid_defaultText6, true);
                    COMBO_CST_BANK.setInputValue(comboGrid_defaultValue7, comboGrid_defaultText7, true);
                    isInit_setSearchComboVal6 = true;
                }
            }
        };
        return options;
    }

    //承租人、担保人账号列表
    var comboGrid_defaultValue7='${accId}';
    var comboGrid_defaultText7 = '${accNo}';
    var isInit_setSearchComboVal7 = true;
    var COMBO_CST_BANK=$("#cstSplAccNoId").ligerComboBox({
        width: 300,
        selectBoxWidth: 430,
        selectBoxHeight: 240,
        valueField: 'id',
        textField: 'accNo',
        isSingleCheck: true,
        condition: {
            labelWidth: 0,
            space: 5,
            fields: [{ name: 'accNo', width: 90, type:'text' , keyName: 'id'}]

        },
        conditionSearchClick: function (a) {
            if (a.rules.length == 0) {
                accNo = '';
            } else {
                accNo = a.rules[0].value;
            }
            COMBO_CST_BANK.grid.options.newPage = 1;
            COMBO_CST_BANK.grid.loadServerData({'accNo': accNo, 'cstId': liger.get("cstSplId").selectedValue, 'page' : '1'});
        },
        grid: getCstSplBankNoGridOptions(true),
        delayLoadGrid: false
    });

    // 获取承租人、担保人账号的列表
    function getCstSplBankNoGridOptions(checkbox){
        var options = {
            url: '<%=path%>/customer/cstbank/initBanks.do',
            columns: [
                { display: 'id', name: 'id', minWidth: 150,hide:true },
                { display: '收款人', name: 'accNm',
                    render: function (rowdata, rowindex, value, column) {
                        value ==null?"":value;
                        var h = '';
                        if(rowdata.audStsCd){
                            if(rowdata.audStsCd!='1'){
                                h+='<i class="ico_flasher"></i>';
                            }
                        }
                        h+=value;
                        return h;
                    },
                    minWidth: 150 },
                { display: '收款账号', name: 'accNo', minWidth: 150 }

            ],
            method: 'get',
            data:null,
            dataAction: 'server',
            root:'rows',
            record:'total',
            pageSize: 10,
            cssClass: "SMALL_grid",
            isSingleCheck: true,
            frozen: false,
            isSelected: function (rowdata) {
                if (comboGrid_defaultValue7 == "") return false;
                if(!isInit_setSearchComboVal7) { //只在初始化时执行一次，在onAfterShowData后改变
                    if(rowdata[COMBO_CST_BANK.options.valueField] == comboGrid_defaultValue7) {
                        return true;
                    }
                };
                return false;
            },
            onAfterShowData: function (currentData) {
                if(!isInit_setSearchComboVal7) { //只在初始化时执行一次，在onAfterShowData后改变
                    COMBO_CST_BANK.setInputValue(comboGrid_defaultValue7, comboGrid_defaultText7, true);
                    isInit_setSearchComboVal7 = true;
                }
            }
        };
        return options;
    }

    //取消
    function cancelBtn(){
        parent.grid.reload();
        parent.$.ligerDialog.close();
        parent.$(".l-dialog,.l-window-mask").css("display","none");
    }

    //保存项目基础信息
    function savePrjBscInfo(){
        var ligerForm = liger.get("basePrdForm1");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var splId;
        var splAccNoId;
        var accNo;
        var splNm;
        var payeeTypCd = ${payeeTypCd};
        if (payeeTypCd == '1') {
            accNo = $("#splAccNoId").val();
            splId =liger.get("splId").selectedValue;
            splAccNoId = liger.get("splAccNoId").selectedValue;
            splNm = $("#splId").val();
        } else {
            accNo = $("#cstSplAccNoId").val();
            splId =liger.get("cstSplId").selectedValue;
            splAccNoId = liger.get("cstSplAccNoId").selectedValue;
            splNm = $("#cstSplId").val();
        }
        var url = '<%=path%>/project/prjbscinfo/saveChangePro.do';
        var wait_dialog;
        $.ajax({
            type : 'post',
            dataType : 'json',
            data : {
                prjPrdId : prjPrdId,
                purpCd : $("#purpCd").val(),
                splId : splId,
                splNm : splNm,
                splAccNoId : splAccNoId,
                payeeTypCd: payeeTypCd,
                accNo : accNo
            },
            url : url,
            beforeSend : function() {
                wait_dialog = $.ligerDialog.SQalert({
                    content : LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type : "waitting"
                });
            },
            success : function(msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({
                        content : msg.info,
                        SQ_type : "success"
                    });
                    parent.grid.reload();
                    parent.$.ligerDialog.close();
                    parent.$(".l-dialog,.l-window-mask").css("display",
                        "none");
                } else {
                    top.$.ligerDialog.SQalert({
                        content : msg.info,
                        SQ_type : "error"
                    });
                }
            }
        });
    }
</script>
<div class="ClearLine"></div>
</body>
</html>
